babl_fish_serialize (Babl *fish, char *dest, int n)
{
char *d = dest;
- if (fish->class_type != BABL_FISH_PATH)
+ if (fish->class_type != BABL_FISH &&
+ fish->class_type != BABL_FISH_PATH)
+ {
return NULL;
+ }
snprintf (d, n, "%s\n%s\n",
babl_get_name (fish->fish.source),
snprintf (d, n, "\tpixels=%li", fish->fish.pixels);
n -= strlen (d);d += strlen (d);
- snprintf (d, n, " cost=%d", (int)fish->fish_path.cost);
- n -= strlen (d);d += strlen (d);
+ if (fish->class_type == BABL_FISH_PATH)
+ {
+ snprintf (d, n, " cost=%d", (int)fish->fish_path.cost);
+ n -= strlen (d);d += strlen (d);
+ }
snprintf (d, n, " error=%f", fish->fish.error);
n -= strlen (d);d += strlen (d);
+ if (fish->class_type == BABL_FISH)
+ {
+ snprintf (d, n, " [reference]");
+ n -= strlen (d);d += strlen (d);
+ }
+
snprintf (d, n, "\n");
n -= strlen (d);d += strlen (d);
- for (int i = 0; i < fish->fish_path.conversion_list->count; i++)
+ if (fish->class_type == BABL_FISH_PATH)
{
- snprintf (d, n, "\t%s\n",
- babl_get_name(fish->fish_path.conversion_list->items[i] ));
- n -= strlen (d);d += strlen (d);
+ for (int i = 0; i < fish->fish_path.conversion_list->count; i++)
+ {
+ snprintf (d, n, "\t%s\n",
+ babl_get_name(fish->fish_path.conversion_list->items[i] ));
+ n -= strlen (d);d += strlen (d);
+ }
}
return dest;
return;
}
- babl = babl_calloc (1, sizeof (BablFishPath) +
- strlen (name) + 1);
- babl_set_destructor (babl, _babl_fish_path_destroy);
-
- babl->class_type = BABL_FISH_PATH;
- babl->instance.id = babl_fish_get_id (from_format, to_format);
- babl->instance.name = ((char *) babl) + sizeof (BablFishPath);
- strcpy (babl->instance.name, name);
- babl->fish.source = from_format;
- babl->fish.destination = to_format;
- babl->fish_path.conversion_list = babl_list_init_with_size (10);
- _babl_fish_prepare_bpp (babl);
- _babl_fish_rig_dispatch (babl);
+ if (strstr (token, "[reference]"))
+ {
+ /* there isn't a suitable path for requested formats,
+ * let's create a dummy BABL_FISH instance and insert
+ * it into the fish database to indicate that such path
+ * does not exist.
+ */
+ const char *name = "X"; /* name does not matter */
+ babl = babl_calloc (1, sizeof (BablFish) + strlen (name) + 1);
+
+ babl->class_type = BABL_FISH;
+ babl->instance.id = babl_fish_get_id (from_format,
+ to_format);
+ babl->instance.name = ((char *) babl) + sizeof (BablFish);
+ strcpy (babl->instance.name, name);
+ babl->fish.source = from_format;
+ babl->fish.destination = to_format;
+ babl->fish.data = (void*) 1; /* signals babl_fish() to
+ * show a "missing fash path"
+ * warning upon the first
+ * lookup
+ */
+ }
+ else
+ {
+ babl = babl_calloc (1, sizeof (BablFishPath) +
+ strlen (name) + 1);
+ babl_set_destructor (babl, _babl_fish_path_destroy);
+
+ babl->class_type = BABL_FISH_PATH;
+ babl->instance.id = babl_fish_get_id (from_format, to_format);
+ babl->instance.name = ((char *) babl) + sizeof (BablFishPath);
+ strcpy (babl->instance.name, name);
+ babl->fish.source = from_format;
+ babl->fish.destination = to_format;
+ babl->fish_path.conversion_list = babl_list_init_with_size (10);
+ _babl_fish_prepare_bpp (babl);
+ _babl_fish_rig_dispatch (babl);
+ }
token2 = strtok_r (&token[1], seps2, &tokp2);
while( token2 != NULL )
}
else if (!strncmp (token2, "cost=", 5))
{
- babl->fish_path.cost = babl_parse_double (token2 + 5);
+ if (babl->class_type == BABL_FISH_PATH)
+ babl->fish_path.cost = babl_parse_double (token2 + 5);
}
else if (!strncmp (token2, "pixels=", 7))
{
token2 = strtok_r (NULL, seps2, &tokp2);
}
}
- else if (to_format && babl)
+ else if (to_format && babl && babl->class_type == BABL_FISH_PATH)
{
Babl *conv = (void*)babl_db_find(babl_conversion_db(), &token[1]);
if (!conv)
}
}
+void
+_babl_fish_missing_fast_path_warning (const Babl *source,
+ const Babl *destination)
+{
+#ifndef BABL_UNSTABLE
+ if (debug_conversions)
+#endif
+ {
+ static int warnings = 0;
+
+ if (_babl_legal_error() <= 0.0000000001)
+ return;
+
+ if (warnings++ == 0)
+ fprintf (stderr,
+"Missing fast-path babl conversion detected, Implementing missing babl fast paths\n"
+"accelerates GEGL, GIMP and other software using babl, warnings are printed on\n"
+"first occurance of formats used where a conversion has to be synthesized\n"
+"programmatically by babl based on format description\n"
+"\n");
+
+ fprintf (stderr, "*WARNING* missing babl fast path(s): \"%s\" to \"%s\"\n",
+ babl_get_name (source),
+ babl_get_name (destination));
+
+ }
+}
+
static Babl *
babl_fish_path2 (const Babl *source,
babl_free (babl);
babl_mutex_unlock (babl_format_mutex);
-#ifndef BABL_UNSTABLE
- if (debug_conversions)
-#endif
- {
- static int warnings = 0;
-
- if (_babl_legal_error() <= 0.0000000001)
- return NULL;
+ _babl_fish_missing_fast_path_warning (source, destination);
- if (warnings++ == 0)
- fprintf (stderr,
-"Missing fast-path babl conversion detected, Implementing missing babl fast paths\n"
-"accelerates GEGL, GIMP and other software using babl, warnings are printed on\n"
-"first occurance of formats used where a conversion has to be synthesized\n"
-"programmatically by babl based on format description\n"
-"\n");
-
- fprintf (stderr, "*WARNING* missing babl fast path(s): \"%s\" to \"%s\"\n",
- babl_get_name (source),
- babl_get_name (destination));
-
- }
return NULL;
}